<template>
	<view >
		<view class="address-button" v-if="JSON.stringify(address) === '{}'">
			<button type="primary" size="mini" @click="chooseAddress">请选择收货地址+</button>
		</view>
		
		<view class="address-box" @click="chooseAddress" v-else>
			<view class="address-box-row1">
				<view class="address-box-row1-left">
					<view class="address-user">收货人：</view>
					<view class="address-user-name">{{address.userName}}</view>
				</view>
				<view class="address-box-row1-right">
					<view class="address-phone">电话：</view>
					<view >{{address.telNumber}}</view>
					<uni-icons type="arrowright" size="18"></uni-icons>
				</view>
			</view>
			
			<view class="address-box-row2">
				<view class="address-box-row2-left">
					收货地址：
				</view>
				<view class="address-box-row2-right">{{addStr}}</view>
			</view>
		</view>
		
		<view>
			<image  class="address-bottom-img" src="/static/address-bottom.png" mode=""></image>
		</view>
		
		
	</view>
</template>

<script>
	import {mapState, mapMutations, mapGetters} from 'vuex'
	export default {
		name:"my-address",
		data() {
			return {
				// address: {}
			};
		},
		methods: {
			...mapMutations('my-user', ['updateAddress']),
			async chooseAddress() {
				const [err, succ] = await uni.chooseAddress().catch(result => result)
				console.log(succ);
				if(err === null && succ.errMsg === 'chooseAddress:ok') {
					// this.address = succ
					this.updateAddress(succ)
				};
			}
		},
		computed: {
			...mapState('my-user', ['address']),
			...mapGetters('my-user', ['addStr'])
		}
	}
</script>

<style lang="scss">
	.address-bottom-img {
		height: 5px;
		width: 100%;
		display: block;
	}
	
	.address-button {
		height: 100px;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.address-box {
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 10px 5px;
		.address-box-row1 {
			display: flex;
			justify-content: space-between;
			align-items: center;
			.address-box-row1-left {
				display: flex;
				align-items: center;
				width: 50%;
				.address-user {
					white-space: nowrap;
				}
				.address-user-name {
					width: 100%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}
			.address-box-row1-right {
				display: flex;
				align-items: center;
				.address-phone {
					white-space: nowrap;
				}
			}
		}
		
		.address-box-row2 {
			display: flex;
			.address-box-row2-left {
				display: flex;
				align-items: center;
				white-space: nowrap;
			}
			.address-box-row2-right {
				
			}
		}
	}
</style>